﻿//ImagePacker
namespace Compression.ImageCompressor
{
    using Compression.SignalCompressor;

    public static class ImagePacker
    {
        public static void Transform(ref float[][] x, ref float[][] y,int size)
        {
            float[] buff = new float[size];
            float[] buff2 = new float[size];
            float[][] tmp = new float[size][];
            for (int i = 0; i < size; i++)
            {
                for (int j = 0; j < size; j++)
                {
                    buff2[j] = x[i][j];
                }
                tmp[i] = new float[size];
                SignalPacker.Transform(ref buff2, ref buff);
                SignalPacker.Reorder(ref buff, ref buff2, false);
                for (int j = 0; j < size; j++)
                {
                    tmp[i][j] = buff2[j];
                }
            }
            for (int j = 0; j < size; j++)
            {
                for (int i = 0; i < size; i++)
                {
                    buff2[i] = tmp[i][j];
                }
                SignalPacker.Transform(ref buff2, ref buff);
                SignalPacker.Reorder(ref buff, ref buff2, false);
                for (int i = 0; i < size; i++)
                {
                    y[i][j] = buff2[i];
                }
            }
        }

        public static void Syntes(ref float[][] x, ref float[][] y, int size)
        {
            float[] buff = new float[size];
            float[] buff2 = new float[size];
            float[][] tmp = new float[size][];
            for (int i = 0; i < size; i++) tmp[i] = new float[size];

            for (int j = 0; j < size; j++)
            {
                for (int i = 0; i < size; i++)
                {
                    buff[i] = x[i][j];
                }
                SignalPacker.Reorder(ref buff, ref buff2, true);
                SignalPacker.Syntes(ref buff2, ref buff);
                for (int i = 0; i < size; i++)
                {
                    tmp[i][j] = buff[i];
                }
            }
            for (int i = 0; i < size; i++)
            {
                for (int j = 0; j < size; j++)
                {
                    buff2[j] = tmp[i][j];
                }
                SignalPacker.Reorder(ref buff2, ref buff, true);
                SignalPacker.Syntes(ref buff, ref buff2);
                for (int j = 0; j < size; j++)
                {
                    y[i][j] = buff2[j];
                }
            }
        }
    }
}
